package net.hnjdzy.newsclient.manager;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import net.hnjdzy.newsclient.entity.News;

import java.io.IOException;
import java.util.List;

public class NewsManager {
    final String url ="http://39.99.228.8:8080/news/servlet/ApiServlet?opr=newslist&tid=";
    //读取新闻的列表
    public List<News> getNewsListByTid(int tid){
        //发起网络请求：OKHttp
        String urlParam =url+tid;
        OkHttpClient client =new OkHttpClient();
        Request request =new Request.Builder().url(urlParam).build();
        try {
            Response response =client.newCall(request).execute();
            String json =response.body().string();
            Log.d("test",json);
            //json解析：FastJSON
            List<News> result = JSON.parseArray(json,News.class);
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }


    }
}
